// 引入一个包
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
// webpack 所有的配置信息
module.exports = {
    // 入口文件
    entry: './src/index.ts',
    //指定打包文件所在的位置
    output: {
        path: path.resolve(__dirname, 'dists'),
        // 打包后的文件
        filename: 'bundle.js',
        environment: {
            arrowFunction: false,
            const:false,
        }
    },
    mode: 'development', // 设置mode
    devServer: {
        static: "./"
    },
    // 指定webpack打包时要使用的模块
    module: {
        rules: [
            {
                //test 指定的时规则生效的文件
                test: /\.ts$/,
                //要使用的loder
                use: [

                    {
                        loader: 'babel-loader',
                        // 设置babel
                        options: {
                            presets: [
                                [
                                    "@babel/preset-env",
                                    {
                                        targets: {
                                            "chrome": "48",
                                            "ie": "10"
                                        },
                                        "corejs": "3",
                                        // 按需加载
                                        "useBuiltIns": "usage"
                                    }
                                ]
                            ]
                        }
                    },
                    'ts-loader'
                ],
                exclude: /node-modules/

            },
            // 指定设置less文件的处理
            {
                test: /\.less$/,
                use: [
                    "style-loader",
                    "css-loader",
                    {
                        loader:'postcss-loader',
                        options:{
                            postcssOptions:{
                                plugins:[
                                    [
                                        "postcss-preset-env",
                                        {
                                            browsers:"last 2 versions",
                                        }
                                    ]
                                ]
                            }
                        }
                    },
                    "less-loader"
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin(
            {
                // title: '1111'
                template: './src/index.html'
            }
        ),
        new CleanWebpackPlugin(),

    ],
    resolve: {
        extensions: ['.ts', '.js']
    }
}